class_name RomanNumeralUtils

const VALUE: Array[int] = [
	1,
	4,
	5,
	9,
	10,
	40,
	50,
	90,
	100,
	400,
	500,
	900,
	1000,
	4000,
	5000,
	9000,
	10000,
	40000,
	50000,
	90000,
	100000,
	400000,
	500000,
	900000,
	1000000,
	4000000,
	5000000,
	9000000,
	10000000,
	40000000,
	50000000,
	90000000,
	100000000,
	400000000,
	500000000,
	900000000,
	1000000000,
	4000000000,
	5000000000,
	9000000000,
	10000000000,
	40000000000,
	50000000000,
	90000000000,
	100000000000,
	400000000000,
	500000000000,
	900000000000,
	1000000000000
]
const SYMBOL: Array[String] = [
	"I",
	"IV",
	"V",
	"IX",
	"X",
	"XL",
	"L",
	"XC",
	"C",
	"CD",
	"D",
	"CM",
	"M",
	"M.V",
	".V",
	"M.X",
	".X",
	".X.L",
	".L",
	".X.C",
	".C",
	".C.D",
	".D",
	".C.M",
	".M",
	".M..V",
	"..V",
	".M..X",
	"..X",
	"..X..L",
	"..L",
	"..X..C",
	"..C",
	"..C..D",
	"..D",
	"..C..M",
	"..M",
	"..M...V",
	"...V",
	"..M...X",
	"...X",
	"...X...L",
	"...L",
	"...X...C",
	"...C",
	"...C...D",
	"...D",
	"...C...M",
	"...M"
]


static func to_roman_numeral(n: int) -> String:
	if n > 4000000:  #4 * VALUE[VALUE.size() - 1]:
		return "∞"

	var out: String = ""
	var i: int = VALUE.size() - 1
	while n:
		var div: int = n / VALUE[i]
		n %= VALUE[i]
		while div:
			out += SYMBOL[i]
			div -= 1
		i -= 1
	return out
